package com.UKIT.airtickets.Service.Handlers

import android.content.Context
import com.UKIT.airtickets.DB.AppDatabase
import com.UKIT.airtickets.Service.LanguageManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class LanguageHandler(private val context: Context) {

    suspend fun changeLanguage(userId: Long) {
        withContext(Dispatchers.IO) {
            try {
                val language = AppDatabase.getDatabase(context).userSettingsDao().getUserSettings(userId.toLong())?.language
                language?.let {
                    LanguageManager.changeLanguage(context, it)
                }
            } catch (e: Exception) {
                android.util.Log.e("Error", e.message.toString())
            }
        }
    }
}
